package com.rmt.www.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import oracle.net.aso.a;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rmt.www.constant.ArtifactType;
import com.rmt.www.dao.ArtifactDao;
import com.rmt.www.dao.ProjectDao;
import com.rmt.www.dao.TraceabilityDao;
import com.rmt.www.dao.UserDao;
import com.rmt.www.service.AdminManageDetailService;
import com.rmt.www.vo.Artifact;
import com.rmt.www.vo.DesignArtifact;
import com.rmt.www.vo.FeatureArtifact;
import com.rmt.www.vo.ImplementationArtifact;
import com.rmt.www.vo.Project;
import com.rmt.www.vo.RequirementArtifact;
import com.rmt.www.vo.TestArtifact;
import com.rmt.www.vo.Traceability;
import com.rmt.www.vo.TraceabilityV2;
import com.rmt.www.vo.User;


public class DependencyAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	public int aid;
	private List<FeatureArtifact> featureDPList;
	private List<RequirementArtifact> requirementDPList;
	private List<DesignArtifact> designDPList;
	private List<ImplementationArtifact> implDPList;
	private List<TestArtifact> testDPList;
	private String artifacttype;
	public String getArtifacttype() {
		return artifacttype;
	}

	public void setArtifacttype(String artifacttype) {
		this.artifacttype = artifacttype;
	}

	private AdminManageDetailService adminManageDetailService;
	
	public String execute(){
		List<TraceabilityV2> list = null;
		
		if (artifacttype.equalsIgnoreCase(ArtifactType.FEATURE)) {
			list = adminManageDetailService.getTraceabilityV2ByTo("featureartifact", aid);
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.REQUIREMENT)) {
			list = adminManageDetailService.getTraceabilityV2ByTo("requirementartifact", aid);
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.DESIGN)) {
			list = adminManageDetailService.getTraceabilityV2ByTo("designartifact", aid);
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.IMPLEMENTATION)) {
			list = adminManageDetailService.getTraceabilityV2ByTo("implartifact", aid);
		} else if (artifacttype.equalsIgnoreCase(ArtifactType.TESTCASE)) {
			list = adminManageDetailService.getTraceabilityV2ByTo("testartifact", aid);
		}
		
		
		featureDPList = new ArrayList<FeatureArtifact>();
		requirementDPList = new ArrayList<RequirementArtifact>();
		designDPList = new ArrayList<DesignArtifact>();
		implDPList = new ArrayList<ImplementationArtifact>();
		testDPList = new ArrayList<TestArtifact>();
		for (int i = 0; i < list.size(); i++) {
			TraceabilityV2 t = list.get(i);
			if (t.getArtifactfromtable().equalsIgnoreCase("featureartifact")) {
				featureDPList.add(adminManageDetailService.getFeatureArtifact(t.getArtifactfromid()));
			} else if (t.getArtifactfromtable().equalsIgnoreCase("requirementartifact")) {
				requirementDPList.add(adminManageDetailService.getRequirementArtifact(t.getArtifactfromid()));
			} else if (t.getArtifactfromtable().equalsIgnoreCase("designartifact")) {
				designDPList.add(adminManageDetailService.getDesignArtifact(t.getArtifactfromid()));
			} else if (t.getArtifactfromtable().equalsIgnoreCase("implartifact")) {
				implDPList.add(adminManageDetailService.getImplementationArtifact(t.getArtifactfromid()));
			} else if (t.getArtifactfromtable().equalsIgnoreCase("testartifact")) {
				testDPList.add(adminManageDetailService.getTestArtifact(t.getArtifactfromid()));
			}
		}
		
		return "success";
	}

	public int getAid() {
		return aid;
	}

	public void setAid(int aid) {
		this.aid = aid;
	}

	public List<FeatureArtifact> getFeatureDPList() {
		return featureDPList;
	}

	public void setFeatureDPList(List<FeatureArtifact> featureDPList) {
		this.featureDPList = featureDPList;
	}

	public List<RequirementArtifact> getRequirementDPList() {
		return requirementDPList;
	}

	public void setRequirementDPList(List<RequirementArtifact> requirementDPList) {
		this.requirementDPList = requirementDPList;
	}

	public List<DesignArtifact> getDesignDPList() {
		return designDPList;
	}

	public void setDesignDPList(List<DesignArtifact> designDPList) {
		this.designDPList = designDPList;
	}

	public List<ImplementationArtifact> getImplDPList() {
		return implDPList;
	}

	public void setImplDPList(List<ImplementationArtifact> implDPList) {
		this.implDPList = implDPList;
	}

	public List<TestArtifact> getTestDPList() {
		return testDPList;
	}

	public void setTestDPList(List<TestArtifact> testDPList) {
		this.testDPList = testDPList;
	}

	public AdminManageDetailService getAdminManageDetailService() {
		return adminManageDetailService;
	}

	public void setAdminManageDetailService(
			AdminManageDetailService adminManageDetailService) {
		this.adminManageDetailService = adminManageDetailService;
	}
}
